package com.example.demo.service;

import com.example.demo.common.ApplicationVariable;
import com.example.demo.common.CommonResult;
import com.example.demo.mapper.UserMapper;
import com.example.demo.model.UserInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-09-03
 * Time: 10:27
 */
@Service
@Slf4j
public class UserService {


    @Autowired
    private UserMapper userMapper;

    public void loadImage(MultipartFile file, String path) {
        //保存文件
        log.info("保存成功：" + path);
        try {
            file.transferTo(new File(ApplicationVariable.ROOT + path));//spring mvc是可以直接throws异常的，框架内部/异常处理器有处理，但是多级调用，耦合度有点高
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public int register(UserInfo userInfo) {
        return userMapper.register(userInfo);
    }

    public UserInfo getUserByUsername(String username) {
        return userMapper.selectByUsername(username);
    }

    public UserInfo getUserByUid(int uid) {
        return userMapper.getUserByUid(uid);
    }
}
